home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / checkfs.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2012-03-27  |  3.9 KB  |  160 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          checkfs
  4. # Required-Start:    checkroot
  5. # Required-Stop:
  6. # Should-Start:      mtab
  7. # Default-Start:     S
  8. # Default-Stop:
  9. # X-Interactive:     true
  10. # Short-Description: Check all filesystems.
  11. ### END INIT INFO
  12.  
  13. # Include /usr/bin in path to find on_ac_power if /usr/ is on the root
  14. # partition.
  15. PATH=/sbin:/bin:/usr/bin
  16. FSCK_LOGFILE=/var/log/fsck/checkfs
  17. [ "$FSCKFIX" ] || FSCKFIX=no
  18. . /lib/init/vars.sh
  19.  
  20. . /lib/lsb/init-functions
  21. . /lib/init/splash-functions-base
  22. . /lib/init/usplash-fsck-functions.sh
  23. . /lib/init/swap-functions.sh
  24.  
  25. do_start () {
  26.     # See if we're on AC Power.  If not, we're not gonna run our
  27.     # check.  If on_ac_power (in /usr/) is unavailable, behave as
  28.     # before and check all file systems needing it.
  29.  
  30. # Disabled AC power check until fsck can be told to only check the
  31. # file system if it is corrupt when running on battery. (bug #526398)
  32. #    if which on_ac_power >/dev/null 2>&1
  33. #    then
  34. #        on_ac_power >/dev/null 2>&1
  35. #        if [ $? -eq 1 ]
  36. #        then
  37. #            [ "$VERBOSE" = no ] || log_success_msg "Running on battery power, so skipping file system check."
  38. #            BAT=yes
  39. #        fi
  40. #    fi
  41.     BAT=""
  42.     fscheck="yes"
  43.  
  44.     if [ -f /fastboot ] || grep -s -w -i "fastboot" /proc/cmdline
  45.     then
  46.         [ "$fscheck" = yes ] && log_warning_msg "Fast boot enabled, so skipping file system check."
  47.         fscheck=no
  48.     fi
  49.  
  50.     #
  51.     # Check the rest of the file systems.
  52.     #
  53.     if [ "$fscheck" = yes ] && [ ! "$BAT" ] && [ "$FSCKTYPES" != "none" ]
  54.     then
  55.  
  56.         # Execute swapon command again, in case there are lvm
  57.         # or md swap partitions.  fsck can suck RAM.
  58.         swaponagain 'lvm and md'
  59.  
  60.         if [ -f /forcefsck ] || grep -s -w -i "forcefsck" /proc/cmdline
  61.         then
  62.             force="-f"
  63.         else
  64.             force=""
  65.         fi
  66.         if [ "$FSCKFIX" = yes ]
  67.         then
  68.             fix="-y"
  69.         else
  70.             fix="-a"
  71.         fi
  72.         spinner="-C"
  73.         case "$TERM" in
  74.           dumb|network|unknown|"")
  75.             spinner=""
  76.             ;;
  77.         esac
  78.         [ "$(uname -m)" = s390 ] && spinner=""  # This should go away
  79.         FSCKTYPES_OPT=""
  80.         [ "$FSCKTYPES" ] && FSCKTYPES_OPT="-t $FSCKTYPES"
  81.         handle_failed_fsck() {
  82.             log_failure_msg "File system check failed. 
  83. A log is being saved in ${FSCK_LOGFILE} if that location is writable. 
  84. Please repair the file system manually."
  85.             log_warning_msg "A maintenance shell will now be started. 
  86. CONTROL-D will terminate this shell and resume system boot."
  87.             # Start a single user shell on the console
  88.             if ! sulogin $CONSOLE
  89.             then
  90.                 log_failure_msg "Attempt to start maintenance shell failed. 
  91. Continuing with system boot in 5 seconds."
  92.                 sleep 5
  93.             fi
  94.         }
  95.         if [ "$VERBOSE" = no ]
  96.         then
  97.             log_action_begin_msg "Checking file systems"
  98.             if usplash_running; then
  99.                 PROGRESS_FILE=`mktemp` || exit 1
  100.                 set -m
  101.                 logsave -s $FSCK_LOGFILE fsck -C3 -R -A $fix $force $FSCKTYPES_OPT >/dev/console 2>&1 3>$PROGRESS_FILE &
  102.                 set +m
  103.                 usplash_progress "$PROGRESS_FILE"
  104.                 rm -f $PROGRESS_FILE
  105.             else
  106.                 splash_start_indefinite
  107.                 logsave -s $FSCK_LOGFILE fsck $spinner -R -A $fix $force $FSCKTYPES_OPT
  108.                 FSCKCODE=$?
  109.                 splash_stop_indefinite
  110.             fi
  111.  
  112.             if [ "$FSCKCODE" -gt 1 ]
  113.             then
  114.                 log_action_end_msg 1 "code $FSCKCODE"
  115.                 handle_failed_fsck
  116.             else
  117.                 log_action_end_msg 0
  118.             fi
  119.         else
  120.             if [ "$FSCKTYPES" ]
  121.             then
  122.                 log_action_msg "Will now check all file systems of types $FSCKTYPES"
  123.             else
  124.                 log_action_msg "Will now check all file systems"
  125.             fi
  126.             splash_start_indefinite
  127.             logsave -s $FSCK_LOGFILE fsck $spinner -V -R -A $fix $force $FSCKTYPES_OPT
  128.             FSCKCODE=$?
  129.             splash_stop_indefinite
  130.             if [ "$FSCKCODE" -gt 1 ]
  131.             then
  132.                 handle_failed_fsck
  133.             else
  134.                 log_success_msg "Done checking file systems. 
  135. A log is being saved in ${FSCK_LOGFILE} if that location is writable."
  136.             fi
  137.         fi
  138.     fi
  139.     rm -f /fastboot /forcefsck 2>/dev/null
  140. }
  141.  
  142. case "$1" in
  143.   start|"")
  144.     do_start
  145.     ;;
  146.   restart|reload|force-reload)
  147.     echo "Error: argument '$1' not supported" >&2
  148.     exit 3
  149.     ;;
  150.   stop)
  151.     # No-op
  152.     ;;
  153.   *)
  154.     echo "Usage: checkfs.sh [start|stop]" >&2
  155.     exit 3
  156.     ;;
  157. esac
  158.  
  159. :
  160.